import os
import pygame

pygame.init()
screen_size = (800, 600)
screen = pygame.display.set_mode(screen_size)

keep_going = True

timer = pygame.time.Clock()
jetPic = pygame.image.load(f"{os.path.dirname(__file__)}/jet_small.png")
jetX = jetPic.get_width()
jetY = jetPic.get_height()

margin = 8
posX = (screen_size[0]-jetX)/2
posY = screen_size[1]-jetY-margin

move = 0

while keep_going:
    for event in pygame.event.get():
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_LEFT:
                move = -1
            elif event.key == pygame.K_RIGHT:
                move = +1
        elif event.type == pygame.KEYUP:
            if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT:
                move = 0
        elif event.type == pygame.QUIT:
            keep_going = False

    posX += move

    if posX < margin:
        posX = margin
    if posX > (screen_size[0]-margin-jetX):
        posX = screen_size[0]-margin-jetX

    screen.fill((0, 0, 0))
    screen.blit(jetPic, (posX, posY))
    pygame.display.update()
    timer.tick(60)

pygame.quit()